package src.四则运算;

import java.util.Random;
import java.util.Stack;

public class QuestionGenerator {
    protected String question, f, suffixOutput;
    protected Integer a, b, c;
    protected Character operator, operator2, operator3;
    private int operatorIndex, operatorIndex2, operatorIndex3;
    private double judgeFraction, judgeBrackets;
    private char[] opr = {'+', '-', '*', '/'};

    public QuestionGenerator() {
        question = "";
    }

    public String getQuestion(int level) {
        switch (level) {
            //等级一
            case 1:
                Random generator1 = new Random();
                a = generator1.nextInt(10) + 1;
                b = generator1.nextInt(10) + 1;
                operatorIndex = generator1.nextInt(4);
                operator = opr[operatorIndex];
                question = a + "" + operator + "" + b + " ";
                return question;
            //等级二
            case 2:
                Random generator2 = new Random();
                Random determination1 = new Random();
                judgeFraction = determination1.nextFloat();
                if (judgeFraction > 0.4) {
                    a = generator2.nextInt(10) + 1;
                    operatorIndex = generator2.nextInt(4);
                    operator = opr[operatorIndex];
                    RationalNumber fraction = new RationalNumber();
                    f = fraction.toString();
                    question = a + "" + operator + "" + f + " ";
                } else {
                    a = generator2.nextInt(10) + 1;
                    b = generator2.nextInt(10) + 1;
                    operatorIndex = generator2.nextInt(4);
                    operator = opr[operatorIndex];
                    question = a + "" + operator + "" + b + " ";
                }
                return question;
            //等级三
            case 3:
                Random generator3 = new Random();
                Random determination2 = new Random();
                judgeFraction = determination2.nextFloat();
                if (judgeFraction > 0.6) {
                    a = generator3.nextInt(15) + 1;
                    b = generator3.nextInt(15) + 1;
                    operatorIndex = generator3.nextInt(4);
                    operatorIndex2 = generator3.nextInt(4);
                    operator = opr[operatorIndex];
                    operator2 = opr[operatorIndex2];
                    RationalNumber fraction = new RationalNumber();
                    f = fraction.toString();
                    question = a + "" + operator + "" + b + "" + operator2 + "" + f + " ";
                } else {
                    a = generator3.nextInt(15) + 1;
                    b = generator3.nextInt(15) + 1;
                    c = generator3.nextInt(20) + 1;
                    operatorIndex = generator3.nextInt(4);
                    operatorIndex2 = generator3.nextInt(4);
                    operator = opr[operatorIndex];
                    operator2 = opr[operatorIndex2];
                    question = a + "" + operator + "" + b + "" + operator2 + "" + c + " ";
                }
                return question;
            //等级四
            case 4:
                Random generator4 = new Random();
                Random determination3 = new Random();
                judgeFraction = determination3.nextFloat();
                if (judgeFraction > 0.4) {
                    a = generator4.nextInt(15) + 1;
                    b = generator4.nextInt(15) + 1;
                    operatorIndex = generator4.nextInt(4);
                    operatorIndex2 = generator4.nextInt(4);
                    operator = opr[operatorIndex];
                    operator2 = opr[operatorIndex2];
                    RationalNumber fraction = new RationalNumber();
                    f = fraction.toString();
                    question = "(" + a + "" + operator + "" + b + ")" + operator2 + "" + f + " ";
                } else {
                    a = generator4.nextInt(15) + 1;
                    b = generator4.nextInt(15) + 1;
                    c = generator4.nextInt(20) + 1;
                    operatorIndex = generator4.nextInt(4);
                    operatorIndex2 = generator4.nextInt(4);
                    operator = opr[operatorIndex];
                    operator2 = opr[operatorIndex2];
                    question = "(" + a + "" + operator + "" + b + ")" + operator2 + "" + c + " ";
                }
                return question;
            //等级四
            case 5:
                Random generator5 = new Random();
                Random determination4 = new Random();
                judgeBrackets = determination4.nextFloat();
                if (judgeBrackets <= 0.5) {
                    a = generator5.nextInt(15) + 1;
                    b = generator5.nextInt(15) + 1;
                    c = generator5.nextInt(15) + 1;
                    operatorIndex = generator5.nextInt(4);
                    operatorIndex2 = generator5.nextInt(4);
                    operatorIndex3 = generator5.nextInt(4);
                    operator = opr[operatorIndex];
                    operator2 = opr[operatorIndex2];
                    operator3 = opr[operatorIndex3];
                    RationalNumber fraction = new RationalNumber();
                    f = fraction.toString();
                    question = "(" + a + "" + operator + "" + b + ")" + operator2 + "" + f + "" + operator3 + "" + c + " ";
                } else {
                    a = generator5.nextInt(15) + 1;
                    b = generator5.nextInt(15) + 1;
                    c = generator5.nextInt(15) + 1;
                    operatorIndex = generator5.nextInt(4);
                    operatorIndex2 = generator5.nextInt(4);
                    operatorIndex3 = generator5.nextInt(4);
                    operator = opr[operatorIndex];
                    operator2 = opr[operatorIndex2];
                    operator3 = opr[operatorIndex3];
                    RationalNumber fraction = new RationalNumber();
                    f = fraction.toString();
                    question = a + "" + operator + "(" + b + "" + operator2 + "" + f + ")" + operator3 + "" + c + " ";
                }
                return question;

            default:
                return "错误题目等级！！\n题目等级1-5\n请输入有效的题目等级";
        }
    }


}
